package Test;

import java.util.ArrayList;
import java.util.List;

public class test10 {
        List<String> ret = new ArrayList<>();
        String[] s = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
        public List<String> letterCombinations(String digits) {
            int n = digits.length();
            if(n==0) return ret;
            char[] ch = digits.toCharArray();
            //遍历到第i个位置
            dfs(0,ch);
            return ret;
        }
        StringBuffer path = new StringBuffer();
        public void dfs(int pos,char[] arr){
            if(path.length()==arr.length){
                ret.add(path.toString());
                return;
            }
            char[] str = s[arr[pos]-'0'].toCharArray();
            //遍历第j个位置的所有可能情况
            for(int j=0;j<str.length;j++){
                path.append(str[j]);
                dfs(pos+1,arr);
                path.deleteCharAt(path.length()-1);
            }
        }

    public static void main(String[] args) {
        test10 t = new test10();
        String s = "23";
        List<String> strings = t.letterCombinations(s);
        System.out.println(strings);
    }

}
